<template>
  <component :is="componentName" :id="rowId" @subPage="subPage"></component>
</template>
<script setup lang="ts" name="accountManageAdmin">
import AnnounceTable from './announceTable.vue'
import AnnounceForm from './announceForm.vue'
import { useCommonStore, useCommonStoreOut } from '@/store/modules/common'
import AnnounceDetail from '@/views/components/announceDetail/index.vue'

let rowId: undefined | number = undefined
const componentName: Record<string, any> = ref(AnnounceTable)
const pageList = [AnnounceTable, AnnounceForm, AnnounceDetail]
const commonStore = useCommonStore()
const commonStoreOut = useCommonStoreOut()

const subPage = async (index: number, id?: number) => {
  componentName.value = pageList[index]
  if (index === 0) {
    commonStoreOut.setFormData(null)
  }
  if (index === 2) {
    rowId = id
  }
}
onMounted(() => {
  if (commonStore.getFormData?.index) {
    subPage(commonStore.getFormData?.index)
  }
})
</script>
